(function($){	
  $.fn.dragBack = function(options) {  
	  
	  var settings = {
		      'parent' : this.parent(),
		      'widthType' : 'this',
		      'duration' : 'slow', // fast
		      'easing' : 'linear' //linear
		    };
	  
	  return this.each(function() {  
		 
		  if ( options ) { 
			  $.extend( settings, options );
		  }
		  
    	var $this = $(this);
    	var width = 0;
		if(settings.widthType == "this") {
			width = $this.width();
		} else if(settings.widthType == "children") {
			$this.children().each(function() {
				width += $(this).width();
			});
		} else {
			alert("Wrong dragback 'widthType' parameter value: '" + settings.widthType + "'");
		}

    	if (width < settings.parent.width()) {
    		$this.animate({
				"left" : "+=" + ((settings.parent.width()/2) - (width/2) - $this.position().left) + "px"
			}, settings.duration, settings.easing);
    	} else {
			if($this.position().left > 0)
				$this.animate({
					"left" : "-=" + $this.position().left + "px"
				}, settings.duration, settings.easing);
      	
			if(settings.parent.width() > width + $this.position().left) {
    			$this.animate({
    				"left": "+="+(settings.parent.width()+Math.abs($this.position().left)-width)+"px"
    			}, settings.duration, settings.easing);
    		}
    	}
    	//alert(width);
    	//alert(settings.parent.width() + " " + width + " " + $this.position().left);
    	//alert($this.position().left);
    	});
   };
})(jQuery);